Tag: Array
JavaScript Array Functions
Map, reduce, and filter are all array methods in JavaScript. Each one will iterate over an array and perform a transformation or computation. Each will return a new array based on the result of the function. Map The map() method is used to create a new array from an existing one, applying a function to each… Continue reading JavaScript Array Functions
Array Merge/ Combine in JS
Merge without removing duplicate elements -> Using concat() Method: The concat() method accepts arrays as arguments and returns the merged array. // with elements of nums1 and returns the // combined array – combinedSum arraylet combinedNums = nums1.concat(nums2, nums3);// More readable formlet combinedNums = [].concat(nums1, nums2, nums3); -> Using spread operator: Spread operator spreads the value of the array into… Continue reading Array Merge/ Combine in JS
Remove array values
To remove values from array in js use _.reject on array. From array ‘categoryArray’ remove values equal to variable ‘hideCategory’.var categoryArray = originalRet.categories[1].categories;categoryArray= _.reject(categoryArray, function (method) { return method.text==hideCategory; });