advanced data manipulation javascript code example
Example 1: advanced data manipulation javascript
var array = [“blue”, “green”, “green”, “black”, “orange”, “blue”, “green”, “red”];var uniqueArray = [];uniqueArray = array.filter((element, index, array)=>{ return array.indexOf(element) === index;})console.log(uniqueArray)["blue", "green", "black", "orange", "red"]
Example 2: advanced data manipulation javascript
var flattenedArray = [];var coloursArray = [ [“blue”, “green”], [“green”, “black”, “orange”, “blue”], [“green”, “red”] ]flattenedArray = coloursArray.reduce( (total, subArray)=>{ return total.concat(subArray)},[]);console.log(flattenedArray)["blue", "green", "green", "black", "orange", "blue", "green", "red"]