티스토리 뷰
아래의 코드는 제가 간단하게 만든거라 let, const 등이 없으니
혹시 필요하면 변수명이나 이런건 수정해서 사용하면 됩니다.
해당 코드는
객체안에 배열이 있고, 그 배열안에 또 배열이 있는 경우인데
inner의 n번째 배열의 값과 다른 객체의 배열과 값을 비교하려고 만든 코드이다.
array_other과 array_inner_2의 array_name이 일치하는 경우
일치하는 객체를 matchArray에 담고, 있는 경우 실행되게끔 만들어두었고
index를 알아야 array_other 값을 변경하기 때문에 indexOf로 index를 찾아서
필요한 조건을 걸도록 해두었다.
array_outer : {
array_inner_1 : Array(20)
array_inner_2 : Array(10)
array_inner_3 : Array(8)
}
array_other : Array(10)
array_outer.array_inner_2.forEach(obj_a => {
let matchArray = array_other.find(obj_b => obj_a.array_name === obj_b.array_name);
if (matchArray) {
let index = array_other.indexOf(matchArray);
if (matchArray.content !== 'find_content') {
array_other[index].value = obj_a.value;
} else {
array_other[index].value = 'chage_content'
}
}
}
'Js' 카테고리의 다른 글
JS - 정규식 테스트 배열 혹은 KEY로 하기 / 얕은 복사, 깊은 복사 - (0) | 2024.03.09 |
---|---|
[JS] 배열을 객체로 변경 및 Key 조건 확인하여 값 변경하기 (0) | 2024.03.07 |
bubbles / cancelable / dispatchEvent (Uncaught TypeError: Cannot read properties of null) (0) | 2023.09.25 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 개발자질문
- 와이어샤크문법
- 고유식별자
- invokeMethod
- 서버포트설정
- computed
- selectpicker
- PathVariable
- 파일전송프로토콜
- springMVC #DTO #VO #DAO
- uuid
- pcap저장
- 로컬에서서버
- selectOption
- APP SCRIPT
- SCP 명령어
- 부트스트랩
- 프론트엔드 #
- How to generate an uuid in google sheet?
- 개발자면접질문
- 파라미터받는법
- vue.js
- ReflectionTestUtils
- 스프링프레임워크
- 패킷캡쳐하는법
- 리눅스
- vue라이프사이클
- 구글스프레드시트
- nextTick
- centos7
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
글 보관함