问题 I have an array like: var array = [1, 2, undefined, undefined, 7, undefined] and need to replace all undefined values with "-" . The result should be: var resultArray = [1, 2, "-", "-", 7, "-"] I think there is a simple solution, but I couldn't find one. 回答1: You could check for undefined and take '-' , otherwise the value and use Array#map for getting a new array. var array = [1, 2, undefined, undefined, 7, undefined], result = array.map(v => v === undefined ? '-' : v); console.log(result);