JavaScript Array methods

let array =['a', 'b', 'c'];
array.forEach(element => console.log(element));
output
> "a"
> "b"
> "c"
let arr= [1, 2, 3];
let mapMethod = arr.map(a=> a*2);
console.log(mapMethod);
output
> [2, 4, 6]
const words = ['spring', 'summer', 'element', 'mango'];
const result = words.filter(word => word.length < 6);
console.log(result);
output
['spring', 'summer', 'mango']
const numbers = [1, 2, 3, 4, 5];
const total = number.reduce(sum, 0);
function sum(accumulator, value){
return accumutaor + value;
}
console.log(total);
output
>15
const arr = [1, 2, 3, 4, 5];const num = arr.slice(1,4);
console.log(num);
output
[ 2, 3, 4 ]
const arr = [1, 2, 3, 4, 5];const deleted = arr.splice(2, 3);console.log(arr);output
[ 1, 2 ]
const names = ['pop', 'carry', 'minaty', 'abdul'];names.sort();console.log(names);output
[ 'abdul', 'carry', 'minaty', 'pop' ]
const a = [1, 2, 3];const b = [4, 5, 6];const c = a.concat(b);console.log(c);output
[ 1, 2, 3, 4, 5, 6 ]
const num = [1, 2, 3];num.fill(0);console.log(num);output[ 0, 0, 0 ]
const names = ['pop', 'carry', 'minaty', 'abdul'];const res = names.includes('abdul');console.log(res);output
true

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store