Arrays are are great to store multiple elements. JavaScript Splice helps to cut down huge chunk of array and select some specific elements using the index(s) as limitation. Compare this two codes

constarray = this.testimonys; for (let key in array) { if (array[key].id < 6) { fiveTestimony.push({ tid: array[key].id, msg: array[key].msg, name: array[key].name, occupation: array[key].occupation }); }}

Using the for method, we loop through the array of and populated the second array using the array push. but below is how to use the JavaScript splice to do the same and select exactly 5 items.

How to use JavaScript Splice

1. Just make sure you have the array 

2. Secondly use the index to make selections. Below is a good example of what to do.

const allTestimonies = this.testimonys.splice(0, 5);