zoukankan      html  css  js  c++  java
  • 数组,对象遍历

    一.for-in

     1.遍历数组:
       for(item in array) { 
            console.info(array[item])
         }
    item =>下标
    2.遍历对象
    for(item in obj) { 
            console.info(item);
          }
    item =>属性名
    二.forEach
    1.遍历数组
    array.forEach(function(v, i, a) {
            console.log(i);
      });
    v =>数组的每一项
    i =>下标
    a =>数组本身
     一个参数:
    array1.forEach(function(key) {
            console.log(key);
          });
    key =>数组的每一项内容
    三.for-of
    1.遍历数组
    for(let item of array) {
            console.info(item.name)
          }
    item =>数组的每一项
    2.遍历字符串,(替换,查找)
    for(item of st) {
            console.info(item)
          }
    item =>字符串的每一个拆分值
    3.部署了 Iterator 接口的对象
        const map = new Map();
        map.set('first', 'hello');
        map.set('second', 'world');
        for(let keys of map){
          console.info(keys)
        }
    key => 每一项键值对,以数组形式返回:["first","hellow"]
    四.json转换
         var jsonString ='{"1":"909","2":"409"}'
          var jsonObj1 =JSON.parse(jsonString)
          // 这种方式不安全,eval会执行json串中的表达式
          var jsonObj = eval('(' + jsonString + ')')
          var toString = JSON.stringify(jsonObj)
          console.info(jsonObj1)
          console.info(jsonObj)
          console.info(toString)
    五.概念
    1.json串 var jsonString ='{"1":"909","2":"409"}'
    2.json对象 var jsonString ={"1":"909","2":"409"}
    3.json数组对象 var jsonString =[{"1":"909","2":"409"},{"1":"909","2":"409"}]
  • 相关阅读:
    poj 1860 最短路—Bellman-Ford算法
    poj 3083 dfs+bfs最短路
    poj 2049 Finding Nemo(bfs+优先队列)
    Codeforces 685B 树形dp
    Codeforces 679B
    hdu 5695 拓扑排序裸题
    hdu 5690 矩阵快速幂/循环节
    《概率》第一卷( 修订和补充第三版)施利亚耶夫著 周概荣译本 勘误
    HDU 2124 Repair the Wall
    HDU 1198 Farm Irrigation
  • 原文地址:https://www.cnblogs.com/LWJ-booke/p/8487030.html
Copyright © 2011-2022 走看看