mobile ecommerce development

JavaScript Tips for Every Web Developer

This article will cover JavaScript tips that web developers can use to save time and money.

Flatten arrays

//flatten array of array
var array = [435, 344, [1, 2, [34, 56, 67, [4322, 1245], 900]], 845, [30257]]
array.flat(Infinity)
// output:
// [435, 344, 1, 2, 34, 56, 67, 4322, 1245, 900, 845, 30257]

Sort alphabetically

//sort alphabeticallyfunction alphabetSort(arr) {
return arr.sort((a, b) => a.localeCompare(b)); }
let array = ["d", "c", "b", "a"]
console.log(alphabetSort(array))
// ["a", "b", "c", "d"]

Eliminate duplicates

const ReDuplicates = array => [...new Set(array)];console.log(ReDuplicates([200,200,399,399,400,500,600,600])) // [200,399,400,600]
Get in touch