0
0

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 1 year has passed since last update.

jQuery JSON取り回し

Posted at

フロントエンド側でのJSON取り回しサンプル

// JSONデータを定義
const jsonSample = [
    { "name": "john", "age": "28", "country": "united states" },
    { "name": "pierre", "age": "25", "country": "france" },
    { "name": "wang", "age": "37", "country": "china" }
];
console.log("original object: ", jsonSample);

// JSON要素を追加
jsonSample.push({"name": "patrick", "age": "33", "country": "united kingdom"})
console.log("pushed: ", jsonSample);

// JSON要素を削除
// 先頭から削除
jsonSample.shift();
// 末尾から削除
jsonSample.pop();
console.log("popped: ", jsonSample);

// JSONデータのフィルタリング
var jsonFiltered = jsonSample.filter(function (j){
    return j.country != "china";
});
console.log("filtered by country is not 'china': ", jsonFiltered);

// JSONプロパティの削除
var jsonSlimed = jsonFiltered;
for(let i = 0; i < jsonSlimed.length; i++){ delete jsonSlimed[i].age; }
console.log("property age deleted: ", jsonSlimed);
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?