文章90
标签1
分类38

JavaScript 将一个数组的每一个对象指定关键词存入另一个数组arry.map(item=>item.关键字)

const arry=[{
    id:1
},
{
    id:2
}]

console.log(arry);
//原本数据[ { id: 1 }, { id: 2 } ]


const arry2=arry.map(item=>item.id)
//item只是将arry数据赋给item再依次处理
console.log(arry2);
//处理以后[ 1, 2 ]


将多个关键字存在其他关键字重新命名或者多组存储:这里记住map(item=>({}))里面结构不能少()

结构const arry2=arry.map(item=>({

gjz1:item.??,

gjz2:item.??

}))

注意:是依次处理每一个对象,将这些对象转为其他关键字后存入数组!!!!

下面就是先处理{ id: '0', name: '张' }转为 id2:text.id,name2:text.name为一个对象再存入数组再处理下一个对象

 const ttt = [
 { id: '0', name: '张' },
 { id: '1', name: '刘' },
// 更多数据...
 ];

   const b=ttt.map(text=>({
  id2:text.id,
  name2:text.name
    }))
    console.log(b);

结果[ { id2: '0', name2: '张' }, { id2: '1', name2: '刘' } ]

nodejs get请求axios

const axios = require("axios")
//axios.get("网站")
axios.get("https://www.baidu.com/")
.then(function(response){
    console.log(response.data);//使用函数function获取返回服务器请求数据,获取data数据,response可以缩写res
    //另外一种简化res=>{}
}).catch(error=>{
    console.log(error);//捕获错误
})

//带参数请求 - 关键字params
//格式
// params:{
//     word1:"",
//     .....
// }
//axios.get("url",{paramms:{
// id:"",
// name:""
// }})
axios.get("https://www.baidu.com/",{
    paramas:{
        Item_ID:1000,
    }
}).then(res=>{
    console.log(res.data);
}).catch(error=>{
    console.log(error);
})



//Post请求将get换成post axios.post


global全局

#global 参数   修改全局变量

x=5


def 普通函数():
    #这里就是只用这部分的x,没有使用外面的
    x=9
    print(x)

def 修改函数():
    global x#这里就修改了值
    x+=5
    print(x)


普通函数()
修改函数()
print(x)#这里就显示了全局修改为10

数据分割处理

#取前面几位就[:位数]
text="你好我是py程序"
取前2位=text[:2]
print(取前2位)

#取后面几位就[负号 位数 :]
取后2位=text[-2:]
print(取后2位)


# 分割spilt("分割的字符串")  比如分割py
分割py=text.split("py")
print(分割py)#变成数组按需求取

With语句

该语句就是不用关闭文件

 """
fp=open("./withtest.txt",'r')
print(fp.read())
fp.close()
"""

#./表示当前目录

#with实现   encoding="UTF-8" 打开中文的格式输出
with open('模块/常见模块.py','r',encoding="UTF-8") as fp:
    print(fp.read())




">