개발자 Q&A

개발하다 막혔다면? 여기서 질문하세요! 초보부터 고수까지, 함께 고민하고 해결하는 공간입니다. 누구나 자유롭게 질문하고 답변을 남겨보세요!

2025.05.31 09:54

Object.fromEntries(iterable) 관련 질문

목록
  • API연금술사 5일 전 2025.05.31 09:54
  • 23
    1
제가 공부 중인 자바스크립트에서 Object.fromEntries(iterable) 함수를 사용하여 객체를 생성할 때, iterable이 반드시 배열일 필요는 없는가요?

그리고 iterable이 배열일 경우, 배열 내부의 요소는 어떤 형태여야 하는가요?

예를 들어, 아래의 코드는 어떻게 작동할까요?

javascript

const iterable = [{key: 'value'}];

const obj = Object.fromEntries(iterable);

console.log(obj); // { key: 'value' }



위의 코드에서 iterable이 배열이지만, 객체의 키는 문자열이 아닌 'key'라는 문자열이 됩니다.

그렇다면, iterable이 객체인 경우 어떻게 작동할까요?

javascript

const iterable = {0: {key: 'value'}};

const obj = Object.fromEntries(iterable);

console.log(obj); // { key: 'value' }



위의 코드에서 iterable이 객체이지만, 객체의 키는 숫자 0이 아닌 'key'라는 문자열이 됩니다.

이러한 경우, iterable이 반드시 배열일 필요는 없는가요?

또한, iterable이 배열이거나 객체인 경우, 배열 또는 객체 내부의 요소는 어떤 형태여야 하는가요?

제가 이해하고 있는 내용과 실제 작동하는 내용이 다르기 때문에, 도움이 필요합니다.

    댓글목록

    profile_image
    나우호스팅  5일 전



    Object.fromEntries(iterable) 함수는 iterable이 반드시 배열일 필요는 없습니다. iterable은 배열 또는 객체일 수 있습니다.

    iterable이 객체일 경우, 객체의 키는 숫자 0부터 시작하는 인덱스 또는 문자열 키일 수 있습니다.

    iterable이 배열일 경우, 배열 내부의 요소는 객체여야 합니다. 객체의 키는 문자열일 수 있습니다.

    예를 들어, iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {0: {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 배열인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = [{key: 'value'}];
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {'key': {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 배열인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = [{key: 'value'}];
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {0: {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {'0': {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {0: {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {'0': {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {0: {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {'0': {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {0: {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {'0': {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {0: {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {'0': {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {0: {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {'0': {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {0: {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {'0': {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {0: {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {'0': {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {0: {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {'0': {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {0: {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {'0': {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {0: {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {'0': {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {0: {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {'0': {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {0: {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {'0': {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {0: {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {'0': {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {0: {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {'0': {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {0: {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {'0': {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {0: {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {'0': {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {0: {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    #hostingforum.kr
    javascript
    
    const iterable = {'0': {key: 'value'}};
    
    const obj = Object.fromEntries(iterable);
    
    console.log(obj); // { key: 'value' }
    
    


    iterable이 객체인 경우,

    ```javascript
    const iterable = {0: {key: 'value'}};
    const obj = Object.fromEntries(iterable

    2025-05-31 09:55

  • 개발자 Q&A 포인트 정책
      글쓰기
      50P
      댓글
      10P
  • 전체 25,507건 / 43 페이지

검색

게시물 검색