+ 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

14th May 2020, 3:55 PM
$hardul B
$hardul B - avatar
5 Answers
+ 3
It may be helpful! array.splice(index,Ā howmany,Ā item1, .....,Ā itemX) Check it https://www.w3schools.com/jsref/jsref_splice.asp
14th May 2020, 4:17 PM
ā£š“†© AnŠŗĪĻ„ soā„“ąø„nŠŗĪ ā™£ļø
ā£š“†© AnŠŗĪĻ„ soā„“ąø„nŠŗĪ ā™£ļø - avatar
14th May 2020, 5:06 PM
$hardul B
$hardul B - avatar
+ 2
It's not doing the same. Try this: console.log(JSON.stringify(val)) to see the difference. The reason is what 怌ļ¼Øļ¼”ļ¼°ļ¼°ļ¼¹ ļ¼“ļ¼Æ ļ¼Øļ¼„ļ¼¬ļ¼°ć€ explained.
14th May 2020, 4:34 PM
Kevin ā˜…
+ 2
Abbou Saad that wasn't the same refer to Kevin's answer and happy to help's answer ..
16th May 2020, 10:05 AM
$hardul B
$hardul B - avatar
+ 1
Splice return array n your array have one element so it's the same
16th May 2020, 9:20 AM
Abbou Saad
Abbou Saad - avatar