[英]How to wrap word in single colon and separate words with comma using javascript
我有以下格式的abc約100個字
高清
鯢
FGG
ASD
依此類推...直到n個數字
我希望它像'abc','def','eft'等...
基本上我想在數據庫中插入一行。
我真的很困惑。 你們能用邏輯幫助我嗎? 我有大量清單無法手動執行。
這是多種方法之一
var source = document.querySelector("pre").textContent;
var items = source.split("\n"); //Split items by new line
items = items.map(function(item) { //Trim whitespace off of each item
return item.trim();
}).filter(function(item) { //Filter out empty items
return item;
});
var list = "'" + items.join("','") + "'"; //Join items together by single quotes and comas, and add single quotes at the beggining and the end
alert(list);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.