+ 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 Respuestas
+ 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
+ 3
Thank you for your answers 「HAPPY TO HELP」 ⒺⓃⒺⓂⓎ Kevin Star Edit :Tried JSON.stringify..now it's clear...
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 「HAPPY TO HELP」 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