2

Есть пример кода,в массиве alarms 5 елементов, как мне узнать в каком элементе массива есть id "66425d90-e1ac-11e8-b1fa-1d0c2fbc6b3e "?(в

alarms: Array(5)
  [0 … 5]
  0:
    ackTs: 0
    clearTs: 0
    createdTime: 1541499120105
    details: {}
    endTs: 1541499120101
    id: {entityType: "ALARM", id: "**66425d90-e1ac-11e8-b1fa-1d0c2fbc6b3e**"}
    name: "Пристрій  "SmartScale" відключено"
    originator: {entityType: "DEVICE", id: "a37a3610-db67-11e8-b1fa-1d0c2fbc6b3e"}
    originatorName: "Силос 5"
    propagate: true
    severity: "CRITICAL"
    startTs: 1541499120101
    status: "ACTIVE_UNACK"
    tenantId: {entityType: "TENANT", id: "209302e0-db67-11e8-9cd5-d98fbfb5c39f"}
    type: "Пристрій  "SmartScale" відключено"
    __proto__: Object
  1:
    ackTs: 0
    clearTs: 0
    createdTime: 1541499120055
    details: {}
    endTs: 1541499120052
    id: {entityType: "ALARM", id: "663abc70-e1ac-11e8-b1fa-1d0c2fbc6b3e"}
    name: "Пристрій  "SmartScale" відключено"
    originator: {entityType: "DEVICE", id: "975a1da0-db67-11e8-b1fa-1d0c2fbc6b3e"}
    originatorName: "Силос 4"
    propagate: true
    severity: "CRITICAL"
    startTs: 1541499120052
    status: "ACTIVE_UNACK"
    tenantId: {entityType: "TENANT", id: "209302e0-db67-11e8-9cd5-d98fbfb5c39f"}
    type: "Пристрій  "SmartScale" відключено"
    __proto__: Object
  2:
    ackTs: 0
    clearTs: 0
    createdTime: 1541499120020
    details: {}
    endTs: 1541499120016
    id: {entityType: "ALARM", id: "66356540-e1ac-11e8-b1fa-1d0c2fbc6b3e"}
    name: "Пристрій  "SmartScale" відключено"
    originator: {entityType: "DEVICE", id: "93536270-db67-11e8-b1fa-1d0c2fbc6b3e"}
    originatorName: "Силос 3"
    propagate: true
    severity: "CRITICAL"
    startTs: 1541499120016
    status: "ACTIVE_UNACK"
    tenantId: {entityType: "TENANT", id: "209302e0-db67-11e8-9cd5-d98fbfb5c39f"}
    type: "Пристрій  "SmartScale" відключено"
    __proto__: Object
  3: {id: {…}, createdTime: 1541499119984, tenantId: {…}, type: "Пристрій     "SmartScale" відключено", originator: {…}, …}
  4: {id: {…}, createdTime: 1541499119935, tenantId: {…}, type: "Пристрій  "SmartScale" відключено", originator: {…}, …}
  5: {id: {…}, createdTime: 1541496660084, tenantId: {…}, type: "Пристрій  "SmartScale" відключено", originator: {…}, …}

1
  • 4
    alarms.findIndex(i => i.id === '66425d90-e1ac-11e8-b1fa-1d0c2fbc6b3e'); 22 ноя 2018 в 13:53

1 ответ 1

0

Если нужно найти непосредственно элемент тогда в масиве alarms

const alarms = [{
  ackTs: 0,
  clearTs: 0,
  createdTime: 1541499120105,
  details: {},
  endTs: 1541499120101,
  id: {entityType: 'ALARM', id: '66425d90-e1ac-11e8-b1fa-1d0c2fbc6b3e'},
  name: 'Пристрій  "SmartScale" відключено',
  originator: {entityType: 'DEVICE', id: 'a37a3610-db67-11e8-b1fa-1d0c2fbc6b3e'},
  originatorName: 'Силос 5',
  propagate: true,
  ...
},
  ...
];

тогда

const result = alarms.find(alarm => alarm.id.id === 'a37a3610-db67-11e8-b1fa-1d0c2fbc6b3e');

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.