Проблема доступа к значению из объекта в массиве с помощью поиска lodash

Brayden Cowell спросил: 07 октября 2018 в 12:07 в: javascript

Итак, у меня есть такой массив

images = [ { "id":8471226, "base64Image":"encodedText" }, ... ]

Но когда я пытаюсь получить доступ к encodedText в моем коде, я получаю неопределенное значение

let id = 8480948
console.log( _.find(images, { id }) ); // undefined
console.log(id)
console.log(images)
const images = [{id: 8471226, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8477463, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8479407, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8477961, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8470619, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8471233, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8471239, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8472382, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8473933, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8475149, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8475151, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8475222, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8475663, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8475791, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8476234, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8476399, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8476474, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8476923, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8477355, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8477425, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8477509, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8477520, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8478401, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8479315, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8480002, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{id: 8480948, base64Image: "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"}]
let id = 8480948
console.log( _.find(images, { id }) ); // undefined
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js"></script>

Когда я щелкаю правой кнопкой мыши по массиву и сохраняю его как глобальную переменную в инструментах разработчика Chrome, он работает как задумано?

Вот изображение вывода

>> p> не так?

[{"id": 8471226, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8477463, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8479407, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8477961, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8470619, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8471233, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8471239, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8472382, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8473933, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8475149, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8475151, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8475222, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8475663, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8475791, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8476234, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8476399, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8476474, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8476923, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8477355, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8477425, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8477509, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8477520, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8478401, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8479315, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8480002, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"},
{"id": 8480948, "base64Image": "KAAAAGgAAAAAAAAwvnlmsC+LHdzl+WxWjRcE1u4G8K"}]

0 ответов