将数组转换为对象
作者:互联网
有时候,出于某种目的,需要将数组转化成对象,一个简单快速的方法是就使用展开运算符号(...):
var fruits = [“banana”, “apple”, “orange”, “watermelon”]; var fruitsObj = { …fruits }; console.log(fruitsObj); // returns {0: “banana”, 1: “apple”, 2: “orange”, 3: “watermelon”, 4: “apple”, 5: “orange”, 6: “grape”, 7: “apple”}
标签:fruitsObj,转换,apple,对象,var,watermelon,数组,orange,banana 来源: https://www.cnblogs.com/ll15888/p/11988415.html