分割字符串
<script>
/* hello */
/* olleh */
var str = "hello";
var arr = str.split("");
arr.reverse();
console.log(arr.join(""))
/* */
var str = "?key=你&age=18"
/*
var obj = {
key:"你",
age:18
}
*/
</script
var str = "?key=你&age=18"
var res = str.slice(1)
var list = res.split("&");
console.log(list)
var key = list[0];
var age = list[1];
key = key.split("=")[1];
age = age.split("=")[1];
var obj ={
key,
age
}
console.log(obj)
</script>
<script>
var url ="https://www.baidu.com?order=hot&cat=你&limit=35&offset=140";
/*
var obj ={
order:hot,
cat:你,
limit:35,
offset:140
}
*/
/* 1、order=hot&cat=你&limit=35&offset=140 */
/* 2、 ['order=hot', 'cat=你', 'limit=35', 'offset=140'] */
var res = url.split("?")[1].split("&");
console.log(res)
var obj = {
}
/* 3、需要让数组的每一项中
第一项作为key
第二项作为value
*/
res.forEach(item=>{
var list = item.split("=");
console.log(list)
obj[list[0]] = list[1];
})
console.log(obj)
</script>