Bambiland
  • Works
  • Blog
  • About
  • Search
  • Line Store
Mobile nav

Javascript 常用語法(持續更新)

字串(String)處理

移除字串最後一個字元


    	stirngObj.slice(0,-1)
    

擷取字串(根據開始及結束索引位置)


    	stirngObj.substring(startIdx, stopIdx) // Idx start from 0
    

擷取字串(根據開始索引位置及長度)


    	stirngObj.substr(startIdx, length) // Idx start from 0, can be minus
        
        // 取最後一個字元
        stirngObj.substr(-1,1)
    

判斷是否有特定字串(區分大小寫)


    	'stringObj'.includes('Obj') // true
    	'stringObj'.includes('obj') // false
    


陣列(Array)處理

移除第一個元素


    	arrayObj.shift();
    

移除最後一個元素


    	arrayObj.pop();
    

加入一個元素在最前方


    	arrayObj.unshift( newElement );
    

加入一個元素在最後


    	arrayObj.push( newElement );
    


函數(Function)

遍歷(map & forEach)


    	const arr = [ 1, 2, 3, 4 ];
        
        // forEach 單純想取出值時使用
        arr.forEach( number =>
        	console.log( number );
        )
		// 1
        // 2
        // 3
        // 4
        
        // map 想改變值時使用
        const plus1 = arr.map(
        	number => number + 1;
        )
        console.log( plus1 ); // [2, 3, 4, 5]
    
Prev
Next

RECOMMEND

line 貼圖分析小幫手超級 Beta 版上線

line 貼圖分析小幫手超級 Beta 版上線

如何在 ckeditor 加上程式碼片段外掛 ( code snippet plugin )

如何在 ckeditor 加上程式碼片段外掛 ( code snippet plugin )

css 筆記 | 用純 css 做逐格動畫

css 筆記 | 用純 css 做逐格動畫

前端超好用外掛推薦 | 常用外掛清單

前端超好用外掛推薦 | 常用外掛清單

Git 常用指令(持續更新)

Git 常用指令(持續更新)

  • Blog
  • About
  • Contact
shareTool
Language

Copyright © Bambiland. Made with Webblize.

  • Works
  • Blog
  • About
Language