+ 5

array containing 0…9

// I have 2 set of codes, both can generate array containing 0-9 var N = 10; var arr1 = Object.keys(Array(N).fill()); // generate array containing 0-9 console.log(JSON.stringify(arr1)); var arr2 = Array.from(Array(N).keys());// generate array containing 0-9 console.log(JSON.stringify(arr1)); if(JSON.stringify(arr1) === JSON.stringify(arr2)) console.log('JSON.stringify(arr1) === JSON.stringify(arr2)'); else console.log('JSON.stringify(arr1) !== JSON.stringify(arr2)'); console.log('When their output are compared, why there are not the same?'); https://code.sololearn.com/WhmWwGp4Ng6o/#js

5th Nov 2017, 4:33 AM
Calviղ
Calviղ - avatar
5 Respuestas
+ 6
I dunno, but it seems keys returnd a string, fill returns numbers
5th Nov 2017, 5:25 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 5
Thanks, though my answer is pure inference as I have no knowledge on JSON
5th Nov 2017, 6:06 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
5th Nov 2017, 5:46 AM
A_Hook
A_Hook - avatar
+ 3
@Pegasus @A_Hook Ohh there are string and number different. Thank you for the answer. it's really helpful.
5th Nov 2017, 6:04 AM
Calviղ
Calviղ - avatar
+ 1
@Pegasus JSON->Java Script Object Notation🙂
5th Nov 2017, 6:09 AM
Jagdeep Thakur
Jagdeep Thakur - avatar