EMDI는 지금도 개발중

JavaScript : map, filter 본문

프론트/JavaScript

JavaScript : map, filter

EMDI 2024. 1. 8. 15:16
          // result [] 배열인 경우
          result = result.map(item => {
            let stateColor = ""
            let stateName = ""
            if (item.state === "0" || item.state === "1" || item.state === "8") {
              stateName = "대기"
              stateColor = "gray"
            } else if (
              item.state === "3" ||
              item.state === "4" ||
              item.state === "6" ||
              item.state === "7" ||
              item.state === "9"
            ) {
              stateName = "취소"
              stateColor = "red"
            } else {
              stateName = "완료"
              stateColor = "blue"
            }
            return {
              ...item,
              처리상태: item.state,
              결과명: stateName,
              결과컬러: stateColor
            }
          })
        }
        const redData = result?.filter(item => item.결과컬러 === "red")
        console.log(redData)
Comments