+ 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 Answers
+ 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 ćļ¼Øļ¼”ļ¼°ļ¼°ļ¼¹ ļ¼“ļ¼Æ ļ¼Øļ¼„ļ¼¬ļ¼°ć
āŗāāŗāā
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 ćļ¼Øļ¼”ļ¼°ļ¼°ļ¼¹ ļ¼“ļ¼Æ ļ¼Øļ¼„ļ¼¬ļ¼°ć 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