Test name | Executions per second |
---|---|
slice | 4309205.5 Ops/sec |
concat | 3314342.5 Ops/sec |
forEach | 4537916.5 Ops/sec |
Traditional For Loop | 4854953.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]);
}