+ 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
5 Respuestas
+ 6
I dunno, but it seems keys returnd a string, fill returns numbers
+ 5
Thanks, though my answer is pure inference as I have no knowledge on JSON
+ 4
object.keys returns an array of strings
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
+ 3
@Pegasus @A_Hook
Ohh there are string and number different. Thank you for the answer. it's really helpful.
+ 1
@Pegasus JSON->Java Script Object Notation🙂