---
title: "Discussion on \"Super Useful Tips & Tricks for JavaScript Developers\" | Hashnode"
description: "Discussion on \"Super Useful Tips & Tricks for JavaScript Developers\". Quick way to mask numbers using slice and ES8 padStart method\nconst creditCard = \"4111111111114321\"; // 16 digit credit card number\nconst lastFourDigits = creditCard.slice(-4); // get last 4 digits\n\n// prepend * to lastFourDigits to make length equal..."
url: "https://hashnode.com/posts/super-useful-tips-and-tricks-for-javascript-developers/60a9eddb20d1f45ceb7eef74"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Super Useful Tips & Tricks for JavaScript Developers](https://blog.yogeshchavan.dev/super-useful-tips-and-tricks-for-javascript-developers?utm_source=hashnode&utm_medium=feed)

Quick way to mask numbers using slice and ES8 padStart method const creditCard = "4111111111114321"; // 16 digit credit card number const lastFourDigits = creditCard.slice(-4); // get last 4 digits // prepend \* to lastFourDigits to make length equal...

May 23, 2021 · 7 min read · blog.yogeshchavan.dev  
Updated Feb 19, 2023  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#reactjs](https://hashnode.com/tag/reactjs)
-   [#codenewbies](https://hashnode.com/tag/codenewbies)
-   [#nodejs](https://hashnode.com/tag/nodejs)

## Written by

[Yogesh Chavan](https://hashnode.com/@myogeshchavan97)

@myogeshchavan97 · India

  
[View profile](https://hashnode.com/@myogeshchavan97)

Full Stack Developer | Freelancer | JavaScript | React | Nodejs. https://yogeshchavan.dev/. Book 1:1 @ hiretheauthor.com/myogeshchavan97

Full Stack Developer | Freelancer | JavaScript | React | Nodejs. Loves sharing knowledge through technical articles. Dev.to: https://dev.to/myogeshchavan97 https://linktr.ee/myogeshchavan97

## Responses 2

Markdown supported · ⌘↵ to post

[Chety](https://hashnode.com/@MereMala)

[May 25, 2021](https://hashnode.com/posts/super-useful-tips-and-tricks-for-javascript-developers/60a9eddb20d1f45ceb7eef74/comment/60ace3eff06aaf7b7c3e1110)

Hey [Yogesh Chavan](https://hashnode.com/@myogeshchavan97)

Good tips thanks. By the way, I can add my two cents to your article.

-   In getting the last element of the array section, in the first example `arr.slice(-1)` will return `[50]` not the value `50`.
-   For checking if it is an array I guess we can also use below code
    
    ```
     const isArray = Object.prototype.toString.call(arr) == "[object Array]"
    ```
    

[Yogesh Chavan](https://hashnode.com/@myogeshchavan97)

[May 25, 2021](https://hashnode.com/posts/super-useful-tips-and-tricks-for-javascript-developers/60a9eddb20d1f45ceb7eef74/comment/60ace3eff06aaf7b7c3e1110#reply-60ace7def06aaf7b7c3e11b7)

[Chety](https://hashnode.com/@MereMala) Thanks for pointing out my mistake. I have updated the article.

And thanks for mentioning another way for Array type check.

[ashpbt 123](https://hashnode.com/@Ashkhan)

[May 28, 2021](https://hashnode.com/posts/super-useful-tips-and-tricks-for-javascript-developers/60a9eddb20d1f45ceb7eef74/comment/60ace3eff06aaf7b7c3e1110#reply-60b08c595c02001765cf53cc)

[Yogesh Chavan](https://hashnode.com/@myogeshchavan97) Thanks for sharing helpful about js.

[Hussein Kizz](https://hashnode.com/@husseinkizz)

[May 23, 2021](https://hashnode.com/posts/super-useful-tips-and-tricks-for-javascript-developers/60a9eddb20d1f45ceb7eef74/comment/60aacd0f20d1f45ceb7f063c)

This article is so useful, cause I recently had an array with something like arr = \[ {name: foo, count:2}, {name2: doe, count:5} \] and I wanted to convert all count values to percentage while maintaining names as they're and get results into a new array, I think the add function and dynamic object trick you have provided here can make it work, I just haven't figured it out. But in all this is awesome, thanks!

[Yogesh Chavan](https://hashnode.com/@myogeshchavan97)

[May 24, 2021](https://hashnode.com/posts/super-useful-tips-and-tricks-for-javascript-developers/60a9eddb20d1f45ceb7eef74/comment/60aacd0f20d1f45ceb7f063c#reply-60ab04e15379f65d10b62066)

Thanks [Hussein Kizz](https://hashnode.com/@husseinkizz). Glad this article was useful to you. But I think I have not understood what you're trying to do. Are you trying to add all count values to calculate the percentage?

[Hussein Kizz](https://hashnode.com/@husseinkizz)

[May 24, 2021](https://hashnode.com/posts/super-useful-tips-and-tricks-for-javascript-developers/60a9eddb20d1f45ceb7eef74/comment/60aacd0f20d1f45ceb7f063c#reply-60ab0bc720d1f45ceb7f0885)

oh yeah [Yogesh Chavan](https://hashnode.com/@myogeshchavan97) thanks, I was trying to do that but I shouted out on the tech twitter community and got help. it's using Array reduce and map and get it to work, here is the tweet: [twitter.com/HusseinKizz/status/1396586056267407362](https://twitter.com/HusseinKizz/status/1396586056267407362)

[Yogesh Chavan](https://hashnode.com/@myogeshchavan97)

[May 24, 2021](https://hashnode.com/posts/super-useful-tips-and-tricks-for-javascript-developers/60a9eddb20d1f45ceb7eef74/comment/60aacd0f20d1f45ceb7f063c#reply-60ab3e6820d1f45ceb7f0cfb)

[Hussein Kizz](https://hashnode.com/@husseinkizz) It's great to hear that you've finally solved the issue
