Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
453 views
in Technique[技术] by (71.8m points)

javascript - 使用JavaScript将新属性(元素)添加到JSON对象(Add new attribute (element) to JSON object using JavaScript)

如何使用JavaScript将新属性(元素)添加到JSON对象?

  ask by translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

JSON stands for JavaScript Object Notation.

(JSON代表JavaScript对象符号。)

A JSON object is really a string that has yet to be turned into the object it represents.

(JSON对象实际上是一个字符串,尚未转换为它表示的对象。)

To add a property to an existing object in JS you could do the following.

(要将属性添加到JS中的现有对象,可以执行以下操作。)

object["property"] = value;

or

(要么)

object.property = value;

If you provide some extra info like exactly what you need to do in context you might get a more tailored answer.

(如果您提供一些额外的信息,例如您在上下文中确实需要做的事情,那么您可能会得到一个更量身定制的答案。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...