JavaScript:把数组变成对象,添加动态key

<template>
  <div>
   把数组变成对象,添加动态key
  </div>

</template>

<script>
  export default {
    name: "",
   props: {
   	dataSource: {}
   }, 
    data() {
      return {
		  data1:[11,22,33,44,55,66,77,88],
		  data2:{}
	  }
    },
    created() {},
    mounted() {
		this.data2 = this.createKeys(this.data1);
		console.log(this.data2);
	},
    methods: {
		createKeys(arr){
			const obj = {};
			arr.forEach((value,index)=>{
				obj['key' + index] = value;
			})
			return obj;
		}
	}
  }
</script>

<style scoped>
  
</style>

效果:

JavaScript:把数组变成对象,添加动态key

 

上一篇:[转]Delphi DLL的创建、静态 以及动态调用


下一篇:http代理工具delphi源码