-
Notifications
You must be signed in to change notification settings - Fork 0
/
arro.js
32 lines (25 loc) · 895 Bytes
/
arro.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import React from "react";
import ReactDOM from "react-dom";
import App from "./components/App";
ReactDOM.render(<App />, document.getElementById("root"));
var numbers = [3, 56, 2, 48, 5];
//Map -Create a new array by doing something with each item in an array.
const newNumbers = numbers.map((x) => {
return x * 2;
});
//Filter - Create a new array by keeping the items that return true.
const newNumber = numbers.filter((num) => {
return num < 10;
});
//Reduce - Accumulate a value by doing something to each item in an array.
var newNu = numbers.reduce((accumulator, currentNumber) => {
return accumulator + currentNumber;
});
////Find - find the first item that matches from an array.
const Number = numbers.find((num) => {
return num > 10;
});
////FindIndex - find the index of the first item that matches.
const newNumb = numbers.findIndex((num) => {
return num > 10;
});