js数组的push操作

今天需要将一个对象push到一个对象数组中

const tableColumns = [
      { title: '级别', dataIndex: 'VIP', width: 200 },
      { title: '比例', dataIndex: 'FEE' },
    ];
const operationColumns = {
      title: '操作', fixed: 'right', key: 'operation',width: 100, render(text, record, key) {
        return (
            <span>
              <a href="javascript:void(0)" onClick={() => { obj.handlerDeleteBtnClick(text, record, key); }} >删除</a>
            </span>
          );
      },
    }

operationColumns 的对象push进去tableColumns

一开始的写法

const columns = oprType !== 3 ? tableColumns.push(operationColumns) : tableColumns;

然后使用的columns,结果报错,后来发现tableColumns.push(operationColumns)返回的是push之后数组的长度

后来进行了修改

oprType !== 3 ? tableColumns.push(operationColumns) : tableColumns;

使用数组tableColumns,这样就没问题了

posted @ 2020-09-30 10:42  無玑小姐  阅读(3603)  评论(0编辑  收藏  举报