zoukankan      html  css  js  c++  java
  • js 数组的基本操作

    1.判断某个值是否在数组中存在(扩展方法)
    Array.prototype.indexOf = function (val) {
      for (var i = 0; i < this.length; i++) {
        if (this[i] == val) return i;
      }
      return -1;
    };
    2.移除某个已存在的值(扩展方法)
    Array.prototype.remove = function (val) {
      var index = this.indexOf(val);
      if (index > -1) {
        this.splice(index, 1);
      }
    };
    3.循环判断某个值是否存在于对象数组中
      var equipments = app.globalData.equipments;
        var bindEquipments=[];
        app.httpService("/GetDevices", { userId: userId},function(result){
        console.log(result)
        // bindEquipments = result;
          equipments.forEach(function (value, index, array) {
              // 如果存在包含指定字段的设备
            result.forEach(function(ralue,rindex,rarray){
              if (ralue["DeviceId"] == value){
                equipments.remove(value);
                bindEquipments.push(ralue);
             }
            })
            });
  • 相关阅读:
    NodeJS优缺点
    移动端触摸相关事件touch、tap、swipe
    vscode使用技巧
    js 字符串转数字
    js 导出Excel
    <!--[if IE 9]> <![endif]-->
    js 异步请求
    关于windows串口处理
    mfc 托盘提示信息添加
    微软的麦克风处理示列代码
  • 原文地址:https://www.cnblogs.com/zmaiwxl/p/8668767.html
Copyright © 2011-2022 走看看