mirror of
https://github.com/NohamR/knowledge-kit.git
synced 2026-05-26 13:41:32 +00:00
feat: 初始化
This commit is contained in:
27
第二部分 Web 前端/2.8.md
Normal file
27
第二部分 Web 前端/2.8.md
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
* 将json转换为对象JSON.parse\(\)函数的第二个参数用来转换解析出的属性
|
||||
|
||||
```
|
||||
JSON.parse('{"name":"lbp","age":"20"}',function(key,value){
|
||||
if(key == "name"){
|
||||
return value + "同学";
|
||||
}
|
||||
return value;
|
||||
});
|
||||
```
|
||||
|
||||
* 将对象转换为json,JSON.stringify\(\)函数的第二个参数用来筛选对象的键值
|
||||
|
||||
```
|
||||
var student = {"name":"小米","age":22,"height":177,"skills":["js","oc"]};
|
||||
function convert(key,value){
|
||||
if (typeof value === "string") {
|
||||
return value.toString().toUpperCase();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
JSON.stringify(student,convert,' ');
|
||||
```
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user