「javaScript」JSON.parse()の引数に関数を利用するサンプル
説明
JSON.parse() メソッドは文字列を JSON として解析し、文字列によって記述されている
JavaScript の値やオブジェクトを構築します。
JSコード
const cityArr = '{"tokyo":"東京","oosaka":"大阪","yokohama":"横浜"}';
const cft = JSON.parse(cityArr,(key,value)=>{
if (key=="yokohama") {
console.log("11");
return "2020";
}
return value ;
} ) ;
console.log(cft);
const cityArr = '{"tokyo":"東京","oosaka":"大阪","yokohama":"横浜"}';
const cft = JSON.parse(cityArr,(key,value)=>{
if (key=="yokohama") {
console.log("11");
return "2020";
}
return value ;
} ) ;
console.log(cft);
const cityArr = '{"tokyo":"東京","oosaka":"大阪","yokohama":"横浜"}'; const cft = JSON.parse(cityArr,(key,value)=>{ if (key=="yokohama") { console.log("11"); return "2020"; } return value ; } ) ; console.log(cft);