JS中数组转字符串,字符串转数组方法合集

2023-05-16

一、字符串转数组:

1、Array.split()

const str = 'hello'
str.split('')    //['h','e','l','l','o']

const str2 = 'hello,world'
str2.split(',')   //[hello,world]

2、[...string] 语句(ES6)

const str = 'hello'
[...str]    //['h','e','l','l','o']

const str2 = 'hello, world'
[...str2]   //['h','e','l','l','o',',','w','o','r','l','d']

3、Array.form()

const str = 'hello'
Array.form(str)     //['h','e','l','l','o']

const str2 = 'hello, world'
Array.form(str2)    //['h','e','l','l','o',',','w','o','r','l','d']

4、Object.assign([], string)

const str = 'hello'
Object.assign([], str)     //['h','e','l','l','o']

const str2 = 'hello, world'
Object.assign([], str2)    //['h','e','l','l','o',',','w','o','r','l','d']

二、数组转字符串

1、Array.join()

const arr = [1,2,3,4]
arr.join()    //'1,2,3,4'
arr.join('')  //'1234'

2、Array.toString()

const arr = [1,2,3,4]
arr.toString()    //'1,2,3,4'

2、Array.toLocaleString()

const arr = [1,2,3,4]
arr. toLocaleString()    //'1,2,3,4'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

JS中数组转字符串,字符串转数组方法合集 的相关文章

随机推荐

  • commonjs模块和es6模块的区别

    es6模块在浏览器端和服务器端都可用 xff0c commonjs只适用于服务端 1 xff0c es6是编译时输出接口 xff08 接口在代码在解析阶段就已经生成 xff09 xff0c commonjs是运行时加载 xff0c 在脚本完
  • uboot的命令体系-2.8.uboot源码分析4-朱有鹏-专题视频课程

    uboot的命令体系 2 8 uboot源码分析4 3793人已学习 课程介绍 本课程为uboot学习的第8部分 xff0c 主要讲解uboot的命令体系 分析了uboot的命令定义和实现的方法 xff0c 教大家自己向uboot中添加自定
  • 浪潮服务器忘记管理口地址,远程配置raid,远程安装系统。

    如果浪潮服务器忘记了管理口地址 xff0c 可以通过设置临时IP地址进行服务器管理 xff08 必须保证服务器之前IPV4的获取方式为DHCP xff09 使用工具 xff1a tftpd32 xff08 网上可直接搜索下载 xff09 x
  • linux命令行——linux快速搜索历史命令

    一 需求描述 在执行命令时 xff0c 对于已经输入的历史命令 xff0c 可以通过关上下键进行翻找 xff0c 如果是最近几条 xff0c 很容易找到 xff0c 如果是很久之前的命令 xff0c 依旧使用上下键查找就会力不从心 二 解决
  • 如何用六步教会你使用python爬虫爬取数据

    前言 xff1a 用python的爬虫爬取数据真的很简单 xff0c 只要掌握这六步就好 xff0c 也不复杂 以前还以为爬虫很难 xff0c 结果一上手 xff0c 从初学到把东西爬下来 xff0c 一个小时都不到就解决了 python爬
  • react实现点击复制

    1 使用浏览器提供的document execCommand 39 copy 39 2 使用copy to clipboard库 document execCommand 34 copy 34 1 document execCommand封
  • zustand

    最近工作中需要用到zustand xff0c 先记录一下学到的demo 安装 xff1a npm install zustand 公共文件store引入 import create from 39 zustand 39 const useS
  • antd获取表单的所有数据

    当我们使用antd的组件的form 表单时 xff0c 数据一般在form中的onFinish 61 onFinish 方法上可以拿到 const Demo 61 61 gt const onFinish 61 values any 61
  • antd使用阿里巴巴矢量图标

    最近需要在antd引入中阿里矢量图标 xff0c 看到几个关于antd使用iconfont的回答 xff0c 其中关于Icon的引入 xff0c 都是写的从antd引入 xff08 不可用 xff09 旧版本 xff1a import Ic
  • antd表单赋值,回显表格数据

    使用 antd 做表格回显数据时 xff0c 会看到文档有写 xff1a 所以我们可以 1 定义hooks const form 61 Form useForm 2 在触发事件中使用 xff0c 以打开模态框赋值为例 const showM
  • react反向代理配置

    官网 xff1a https create react app dev docs proxying api requests in development 安装 npm install http proxy middleware save
  • js立即执行函数写法

    优点 xff1a 1 立即执行 xff0c 不用担心临时变量污染全局变量 xff0c 减少命名 2 方便封装 写法 xff1a function name params console log params 打印 1 1 function
  • uboot的环境变量-2.9.uboot源码分析5-朱有鹏-专题视频课程

    uboot的环境变量 2 9 uboot源码分析5 3347人已学习 课程介绍 本课程为uboot学习的第9部分 xff0c 主要讲解uboot的环境变量的实现原理和环境变量在内存中 SD卡中的存储方法 结合环境变量相关的几个命令的代码分析
  • 输出什么呢?

    let normaLize 61 function params let arr 61 params split g filter v 61 gt v let result 61 let obj 61 result while key 61
  • Pormise

    Promise是一个构造函数 三种状态 xff1a pending xff08 进行中 xff09 fulfilled xff08 已成功 xff09 和rejected xff08 已失败 xff09 xff0c fulfilled和re
  • js删除对象的某个属性

    第一种 xff1a delete const obj 61 name 39 章三 39 age 18 删除age这个属性 delete obj age console log obj name 39 章三 39 第二种 xff08 ES6
  • moment时区转换

    moment js 时区转换 根据本地时区 moment 34 2022 05 31T16 00 00 000Z 34 format 39 YYYY MM DD 39 39 2022 06 01 39
  • TypeScript

    安装 npm install g typescript 安装完成后 xff0c 在控制台运行如下命令 xff0c 检查安装是否成功 3 x xff1a tsc V vscode自动编译 1 生成配置文件tsconfig json tsc i
  • 数组中第一个不重复的值

    var firstUniqChar 61 function s const arr 61 countBy s for const i k of Array from s entries if arr k 61 61 61 1 return
  • JS中数组转字符串,字符串转数组方法合集

    一 字符串转数组 xff1a 1 Array split const str 61 39 hello 39 str split 39 39 39 h 39 39 e 39 39 l 39 39 l 39 39 o 39 const str2