Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const arrayOne = [1,2,3,4,5];
- const arrayTwo = [6,7,8,9];
- const arryObject = [{id: 1, nama: 'restu'}, {id: 2, nama: 'ari'}];
- const value = 0;
- // loop data with map i can create new values from old values
- const arrMap = arrayOne.map(item => item * 2);
- // loop data with foreach cannot create new values from old value
- const arrForeach = arrayOne.forEach(item => item * 2);
- // push new array data with immutabble array
- const arrConcat = arrayOne.concat([...arrayTwo]);
- // alternative - push new array data with immutabble array with spread operator
- const spreadOperator = [...arrayOne, ...arrayTwo];
- // find results values is array iterables
- const arrFind = arrayTwo.find(item => item.nama === 'john doe');
- // filter results values is array literals
- const arrFilter = arrayTwo.filter(item => item.nama === 'john doe');
- // findIndex working with array literals and array iterables
- const arrFindIndex = arrayTwo.findIndex(item => item.id === 2);
- // indexOf working with array literals and not working in array iterables
- const arrFindIndexOf = arrayOne.indexOf(4);
- // some working with array literals and working with array iterables
- const arrSome = arryObject .some(item => item.id === 1);
- // every working with array literals and not working in array iterables
- const arrEvery = arrayOne.every(item => item.id === 3);
- // includes working with array literals and not working in array iterables
- const arrIncludes = arrayOne.includes(4);
- // reduce convert array number literals to single number not for array iterables
- const arrReduce = arrayOne.reduce(item => value += item);
- // delete data with specific value with array literals use with indexOf
- // delete data with specific value with array iterables use with findIndex
- // suport delete multiple deletes value and pop or shift not support mutiple delete value
- const arrSlice = arrayOne.splice(1, 1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement