使用 JavaScript 向 JSON 对象添加新属性(元素) [英] Add new attribute (element) to JSON object using JavaScript

查看:52
本文介绍了使用 JavaScript 向 JSON 对象添加新属性(元素)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do I add new attribute (element) to JSON object using JavaScript?

推荐答案

JSON 代表 JavaScript Object Notation.JSON 对象实际上是一个尚未转化为它所代表的对象的字符串.

JSON stands for JavaScript Object Notation. A JSON object is really a string that has yet to be turned into the object it represents.

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

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

object["property"] = value;

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.

这篇关于使用 JavaScript 向 JSON 对象添加新属性(元素)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆