Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

javascript - 如何从JavaScript对象中删除键? [重复](How do I remove a key from a JavaScript object? [duplicate])

This question already has an answer here:(这个问题已经在这里有了答案:)

Let's say we have an object with this format:(假设我们有一个具有这种格式的对象:)

var thisIsObject= {
   'Cow' : 'Moo',
   'Cat' : 'Meow',
   'Dog' : 'Bark'
};

I wanted to do a function that removes by key:(我想做一个通过键删除的函数:)

removeFromObjectByKey('Cow');
  ask by Martin Ongtangco translate from so

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

1 Answer

0 votes
by (71.8m points)

The delete operator allows you to remove a property from an object.(delete运算符允许您从对象中删除属性。)

The following examples all do the same thing.(以下示例都做同样的事情。)

// Example 1
var key = "Cow";
delete thisIsObject[key]; 

// Example 2
delete thisIsObject["Cow"];

// Example 3
delete thisIsObject.Cow;

If you're interested, read Understanding Delete for an in-depth explanation.(如果您有兴趣,请阅读《 了解删除》以获取详细说明。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...