Created
July 26, 2017 02:51
-
-
Save HereChen/800172ead1b5fd20650ae4323f8bee45 to your computer and use it in GitHub Desktop.
删除对象中key对应值的空格和换行符
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 剔除前后空格和换行符 | |
function trimWrapSpace(obj) { | |
for (var key in obj) { | |
if (obj.hasOwnProperty(key)) { | |
// 如果是字符串, 直接去除末尾空格以及换行符. | |
// 注意变量中的换行符和实际换行 | |
obj[key] = (typeof obj[key] === 'string' || obj[key] instanceof String) ? obj[key].replace(/[\\r\\n]+/g, '').replace(/^\s+|\s+$/g, '') : obj[key]; | |
} | |
} | |
return obj; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment