>  Q&A  >  본문

함수를 연결하여 이 JavaScript 코드를 어떻게 단순화할 수 있습니까?

<p>이러한 함수 호출을 연결하여 단순화하는 방법을 알고 싶습니다. forEach를 연결하고, 푸시하고, 배열을 구조화하고 함께 매핑하는 방법이 있습니까? </p> <pre class="brush:php;toolbar:false;">let selectorsForLoader = ['a', 'b']; loadingElements = []; selectorsForLoader.forEach(선택기 => { loadingElements.push(...Array.from(document.querySelectorAll(selector))); }); 로더 = loadingElements.map(loadingElement => { loadingElement.doSomething(); });</pre> <p>다음은 예입니다: </p> <pre class="brush:php;toolbar:false;">food.map(item => item.type) .reduce((결과, 과일) => { result.push(과일); return [...new Set(결과)]; }, []);</pre> <p><br /></p>
P粉099145710P粉099145710449일 전548

모든 응답(1)나는 대답할 것이다

  • P粉019353247

    P粉0193532472023-07-29 18:29:37

    이건 어떡하지

    으아악

    그런데, 당신이 제시한 "예제"는 다음과 같이 작성되어야 합니다:

    으아악

    회신하다
    0
  • 취소회신하다