【筆記】爲小於10的月份加0

	let month=[1,2,3,4,5,6,7,8,9,10,11,12];
    console.log(month);     //[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
    let newMonth = month.map(item=>('0'+item).substr(-2));    //全部加‘0’,截取倒數兩位
    console.log(newMonth)     //["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章