Skip to main content

Command Palette

Search for a command to run...

Important Javascript functions: Emojis Edition πŸš€

Published
β€’3 min read
Important Javascript functions: Emojis Edition πŸš€

JavaScript functions play a crucial role in web programming, allowing us to perform various operations on data and manipulate arrays and objects efficiently. By understanding and utilizing these functions effectively, you can write cleaner and more concise code, improving the performance and readability of your JavaScript projects

β­• map() function:

The 'map()' function in Javascript allows you to create a new array by applying a function or operation to each element of the existing array. This function returns a new array. It does not modify the original array.

Example: [🟒,🟒,🟒,🟒].map((🟒)=>🟩) 
Output: [🟩,🟩,🟩,🟩]

β­• filter() function:

The 'filter()' function in Javascript allows you to create a new array that contains only the elements from the original array that pass a specific condition. It iterates over each element in the array, applies a provided function to test the condition, and returns a new array with the elements that satisfy the condition. It returns a new array and does not modify the original array.

Example: [πŸ”΄,πŸ”΄,🟑,🟑,🟒,🟒].filter(🟑)
Output: [🟑,🟑]

β­• slice() function:

The slice() function in JavaScript allows you to extract a portion of an array into a new array. It takes two optional parameters: start and end. The start parameter represents the index at which to begin extracting elements (inclusive), and the end parameter represents the index at which to stop extracting elements (exclusive). It returns a new array and does not modify the original array.

Example: [πŸ”΄,🟠,🟑,🟒,πŸ”΅,🟣,🟀,⚫,βšͺ].slice(1,5)
Output: [🟠,🟑,🟒,πŸ”΅]

β­• push() function:

The push() function in Javascript is used to add one or more elements to the end of an array. It modifies the original array by appending the new elements as its last elements.

Example: [πŸ”΄,🟑,🟒].push(πŸ”΅,🟣)
Output: [πŸ”΄,🟑,🟒,πŸ”΅,🟣]

β­• unshift() function:

The unshift() function is used to add one or more elements to the beginning of the array. It modifies the original array by inserting the new elements at the start.

Example: [🟑,🟒,πŸ”΅,πŸ”΄].unshift(🟣)
Output: [🟣,🟑,🟒,πŸ”΅,πŸ”΄]

β­• pop() function:

The pop() function in JavaScript is used to remove the last element from an array. It modifies the original array by removing its last element and returning the removed element.

Example: [πŸ”΅,🟒,🟑,πŸ”΄].pop()
Output: [πŸ”΅,🟒,🟑]

β­• shift() function:

The shift() function is used to remove the first element from an array. It modifies the original array by removing the first element.

Example: [🟣,πŸ”΄,πŸ”΅,🟒,🟑].shift()
Output: [πŸ”΄,πŸ”΅,🟒,🟑]

β­• join() function:

The join() function is used to create a string by concatenating all the elements of an array. It converts each element into a string and joins them together using a specified separator.

Example: [🟑,🟒,πŸ”΄].join("-")
Output: "🟑-🟒-πŸ”΄"

That is it for this blog. Hope this visual aid helped you get a clearer understanding of these functions. Until next time, Happy Coding!