一行代码,实现字符串内容或数组翻转(倒序)。
代码:
var str = "JShaman,专注于JS代码混淆加密。";
console.log("原字符串:",str)
var new_str = str.split("").reverse().join("");
console.log("翻转后的字符串:",new_str);
核心是第3行,使用splite先将字符串转为数组,再用reverse方法进行全部数组内容倒序,再用join方法结合为字符串。
运行效果如下:
特别声明:以上内容(如有图片或视频亦包括在内)为自媒体平台“网易号”用户上传并发布,本平台仅提供信息存储服务。
Notice: The content above (including the pictures and videos if any) is uploaded and posted by a user of NetEase Hao, which is a social media platform and only provides information storage services.