+ 5
[Solved] What is the use of [0] in the following code?
I was trying this code from Stackoverflow which prints all permutations in an array.. Although i didn't get the meaning/use of [0] in the line ch = input.splice(i, 1)[0]; I tried removing [0] from the code.. Still it works.. So what does it do? Question link: https://stackoverflow.com/questions/9960908/permutations-in-javascript https://code.sololearn.com/W0fSZAyWnGuf/?ref=app
5 Respuestas
+ 3
It may be helpful!
array.splice(index, howmany, item1, ....., itemX)
Check it
https://www.w3schools.com/jsref/jsref_splice.asp
+ 3
Thank you for your answers 「HAPPY TO HELP」
ⒺⓃⒺⓂⓎ
Kevin Star
Edit :Tried JSON.stringify..now it's clear...
+ 2
It's not doing the same.
Try this:
console.log(JSON.stringify(val))
to see the difference.
The reason is what 「HAPPY TO HELP」 explained.
+ 2
Abbou Saad that wasn't the same refer to Kevin's answer and happy to help's answer ..
+ 1
Splice return array n your array have one element so it's the same