Test name | Executions per second |
---|---|
slice | 2392203.5 Ops/sec |
splice | 3432711.2 Ops/sec |
concat | 2618688.8 Ops/sec |
for loop | 10168945.0 Ops/sec |
var data = [];
var res = [];
fetch('https://jsonplaceholder.typicode.com/posts')
.then(response => response.json())
.then(json => data = json)
res = data.slice();
res = data.concat();
res = [];
data.forEach(element => res.push(element));
res = [];
for (let i = 0; i < data.length; i++) {
res.push(data[i]);
}