9
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

node.jsでJSONの不要な要素を削除したい

Posted at

rssなんかをJSONに変換していらない要素を消したいケース。

delete jsonObject[key]

で、指定したキーの要素が削除できます。
rssをJSON化してtitleとsummaryとpubdateしか要らない!
というときは以下のように出来ます。
(変数"item"にrssをJSON化したオブジェクトが入っている場合)

var elements = ["title", "summary", "pubdate"]
for(var key in item) {
	if(elements.indexOf(key) < 0) {
		delete item[key];
	}
}
9
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?