简体   繁体   English

用双引号创建数组

[英]create array with double quotes

I'm trying to push following object to an array but it doesn't work as expected.我正在尝试将 object 推送到一个数组,但它没有按预期工作。

var obj = '"'+excep+'"'+":"+'"'+new_time+'"'

When tried with array.push it gives me following output instead of this.当尝试使用 array.push 时,它给了我 output 而不是这个。 "e2022_08_31":"06:00-07:20"

 ["\"e2022_08_31\":\"06:00-07:20\""]

use template literals使用模板文字

const obj = `"${excep}":"${new_time}"`

eg例如

 const arr = [] const excep = "e2022_08_31" const new_time = "06:00-07:20" const obj = `"${excep}":"${new_time}"` arr.push(obj) console.log(arr) console.log(arr[0])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM