An object problem in push

var text_2=["a","b","c","d","e","f"];
        var newarr=[];
        for(var i=0;i<text_2.length;iPP){
                newarr.push({i:text_2[i]});
        }
         console.log(newarr);

Why is the object key from push I: "a"?
clipboard.png
instead of 123456

Nov.02,2021

 var text_2=['a','b','c','d','e','f'];
    var newarr=[];
    for(var i=0;i<text_2.length;iPP){
        newarr.push({[i]:text_2[i]});
    }
     console.log(newarr);
     

clipboard.png


if you write I on key, he will default to the key name I, not the variable I
to {[I]: I}


Why use [] to frame I? Because [the name of the attribute] and the use. The name of the setting property is the same. It's just that the specific scene used is different, so the way to write it is different

look at the code:

var text_2=['a','b','c','d','e','f'];
var newarr=[];
for(var i=0;i<text_2.length;iPP){
    // text_2[i] => a,b,c...
    // i => 0,1,2,3,4...
    newarr.push({[i]: text_2[i]});
}
console.log(newarr);
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3d013-e8ab.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3d013-e8ab.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?