Posts

Showing posts with the label immutable

javascript : Array.clone()

  javascript : Array .clone() Target: Applicable with  Array  Data Type. Description : Clone array of mutable values or immutable values in to a new array without reference. It also clone array of object in to new array of object. Note: logic behind it is JSON.stringify and JSON.parse. Syntax: [] .clone() return duplicate array without reference link of original array. That's mean changes in one not reflect in another. Usase: [1,2,3,4,5].clone() It return new array [1,2,3,4,5] var arr = [1,2,3,4,5]; var arr2 = arr.clone(); arr2 = [1,2,3,4,5] var productList=[{productID:1,productName:'Product One'}, {productID:2,productName:'Product Two'}, {productID:3,productName:'Product Three'}]; var cloneList = productList.clone(); cloneList=[{productID:1,productName:"Product One"}, {productID:2,productName:"Product Two"}, {productID:3,productName:"Product Three"}] Download MYJS.js MyJs is a collection of java script extension methods tha...