How to use the JavaScript Array Methods Playground
- 1. Enter an arrayAny JSON array: numbers, strings or objects.
- 2. Pick a methodIts typical arguments fill in; change them to try your own.
- 3. RunSee what it returns and whether the original array changed.
Why this matters
Array methods are asked about in almost every JavaScript interview, and two questions trip people up most: what does it return? and does it change the original array?
map,filter,slice,concatand the newertoSortedandtoReversedreturn new arrays and leave the original alone.sort,reverse,splice,push,pop,shift,unshiftandfillchange the original, which can cause bugs in React state, where you must not mutate.pushreturns the new length, not the array, andforEachalways returns undefined.
The table under the playground lists every method with what it does and whether it mutates.
Worked example
With the array [5, 12, 8, 130, 44] and filter(x => x > 10), the result is [12,130,44], an array, and the original is unchanged.
Now try sort with no arguments: it returns [12,130,44,5,8], because without a compare function JavaScript sorts items as strings, and "130" comes before "44". The original is changed too (✎ Yes). With (a, b) => a - b you get the numeric order [5,8,12,44,130].
And reduce((sum, x) => sum + x, 0) returns 199, a number. Your code runs in a separate worker with a 2-second limit, so an endless loop can't freeze the page.
Frequently asked questions
Can I use objects?
Yes. For example [{"name":"Asha","age":24}] with map(u => u.name) returns the names.
Why is console.log output shown?
If your callback logs anything, it appears in the result so you can see each step.
Which browsers support toSorted?
All current browsers. Very old ones may say it is not a function.
Is the javascript array methods playground free?
Yes, it is free. Your first run asks for your name and WhatsApp number once. After that, the javascript array methods playground and every other Uncodemy tool open with no form.