개발-IT/Javascript

정리.

바다로그 2020. 12. 18. 13:21
//question  
const dataTest=[
                    {
                        id: 'op',
                        fileName: 'op.md',
                        title: 'When to Use Static Generation v.s. Server-side Rendering',
                        date: '2020-11-02'
                    },
                    {
                        id: 'pre-rendering',
                        fileName: 'pre-rendering.md',
                        title: 'Two Forms of Pre-rendering',
                        date: '2020-01-01'
                    }  
                ]
dataTest.map(({id,fileName,title,date})=>console.log("TEST1",id,fileName,title,date))
dataTest.map((id,fileName,title,date)=>console.log("TEST2",id,fileName,title,date))

// OUTPUT
// TEST1 op op.md When to Use Static Generation v.s. Server-side Rendering 2020-11-02
// TEST1 pre-rendering pre-rendering.md Two Forms of Pre-rendering 2020-01-01
// TEST2 {
//   id: 'op',
//   fileName: 'op.md',
//   title: 'When to Use Static Generation v.s. Server-side Rendering',
//   date: '2020-11-02'
// } 0 [
//   {
//     id: 'op',
//     fileName: 'op.md',
//     title: 'When to Use Static Generation v.s. Server-side Rendering',
//     date: '2020-11-02'
//   },
//   {
//     id: 'pre-rendering',
//     fileName: 'pre-rendering.md',
//     title: 'Two Forms of Pre-rendering',
//     date: '2020-01-01'
//   }
// ] undefined
// TEST2 {
//   id: 'pre-rendering',
//   fileName: 'pre-rendering.md',
//   title: 'Two Forms of Pre-rendering',
//   date: '2020-01-01'
// } 1 [
//   {
//     id: 'op',
//     fileName: 'op.md',
//     title: 'When to Use Static Generation v.s. Server-side Rendering',
//     date: '2020-11-02'
//   },
//   {
//     id: 'pre-rendering',
//     fileName: 'pre-rendering.md',
//     title: 'Two Forms of Pre-rendering',
//     date: '2020-01-01'
//   }
// ] undefined



console.log('sort_test1',[11,2,22,1].sort((a, b) => a - b))
console.log('sort_test2',[11,2,22,1].sort((a,b) =>{
                                            if (a<b){
                                                return -1
                                            }else{
                                                return  1
                                            } 
                                     }
                                )
            )


// OUTPUT
// sort_test1 [ 1, 2, 11, 22 ]
// sort_test2 [ 1, 2, 11, 22 ]

'개발-IT > Javascript' 카테고리의 다른 글

짧은 코드 모음.  (0) 2020.12.04