数组-join(_ :)函数抛出EXC_BAD_ACCESS. var ar1 = [1,2,3]var ar2 = [5,6,7]var res = ar1.join(ar2) 有人遇到过这个问题吗?任何解决方案或建议? 你想要的是什么 var ar1 = [1,2,3]var ar2 = [5,6,7]var res = ar1 + ar
var ar1 = [1,2,3] var ar2 = [5,6,7] var res = ar1.join(ar2)
有人遇到过这个问题吗?任何解决方案或建议?
你想要的是什么var ar1 = [1,2,3] var ar2 = [5,6,7] var res = ar1 + ar2
您通常会使用join()通过在第一级元素之间插入另一个数组中的元素来展平两级数组:
var ar1 = [1,2,3] var ar2 = [[4,5,6],[7,8,9],[10,11,12]] let res = ar1.join(ar2) // [4, 5, 6, 1, 2, 3, 7, 8, 9, 1, 2, 3, 10, 11, 12]
该函数也以相同的方式对字符串起作用:
let ar1 = ["1","2","3"] let res = ".!?".join(ar1) // "1.!?2.!?3"