Javascript rest parameters | SoloLearn: Learn to code for FREE!


Javascript rest parameters

function containsAll(arr) { for (let k = 1; k < arguments.length; k++) { let num = arguments[k]; if (arr.indexOf(num) === -1) { return false; } } return true; } let x = [2, 4, 6, 7]; console.log(containsAll(x, 2, 4, 7));//true console.log(containsAll(x, 6, 4, 9));//false why does first array becomes true while the other one is false since they have the nmber arguements?

3/28/2019 5:38:53 PM

Mas Hairul Adham

4 Answers

New Answer


The function searches all numbes in the array. In the first statement all numbers are found, and true is returned. In the second statement the 9 is not found in the array, so false is returned.


so why did the x is in within the ()


Its a parameter for the function. Its assignt to arr. The other argumeters are accessed via the arguments array.


oh thank you very much