Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Python
- 정렬
- Nest.js
- Express
- TypeScript
- react
- nestjs
- class
- cookie
- 게임
- Dinosaur
- typeORM
- MySQL
- Bull
- flask
- 자료구조
- nodejs
- AWS
- GIT
- 공룡게임
- jest
- dfs
- MongoDB
- Queue
- JavaScript
- game
- OCR
- mongoose
- Sequelize
Archives
- Today
- Total
포시코딩
Array.prototype.find() 본문
728x90
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/find
Array.prototype.find() - JavaScript | MDN
find() 메서드는 주어진 판별 함수를 만족하는 첫 번째 요소의 값을 반환합니다. 그런 요소가 없다면 undefined를 반환합니다.
developer.mozilla.org
오브젝트로 이루어진 배열에서 id 값이 2인 오브젝트를 찾고 싶을 때 쓸 수 있는 문법
let data = [
{
id : 0,
title : "White and Black",
content : "Born in France",
price : 120000
},
{
id : 1,
title : "Red Knit",
content : "Born in Seoul",
price : 110000
},
{
id : 2,
title : "Grey Yordan",
content : "Born in the States",
price : 130000
}
];
data 안에서 id 가 2인 오브젝트의 title 을 찾고 싶을 경우 아래와 같이 하면된다.
let result = data.find( x => x.id == 2 );
console.log(result.title);
728x90
'JavaScript' 카테고리의 다른 글
Promise, async/await을 통한 순차실행 - 작성중 (0) | 2022.12.03 |
---|---|
클립보드에 복사 (0) | 2022.11.09 |
script 파일 불러올 때 쓰는 defer가 뭘까? (async, defer) (0) | 2022.10.19 |
Array.sort() 배열 내 오브젝트 값으로 정렬하기 (0) | 2022.07.08 |
Promise 예제 (0) | 2022.06.18 |