首页 > 解决方案 > 如果我复制并粘贴它,为什么它没有 console.log() 任何东西?

问题描述

我在Glitch上运行此代码以在对话前添加 \n,如果我在 toFormat 中的单词所在的空间中输入一些内容,它可以正常工作,但如果我将某些内容复制并粘贴到其中,它不会 console.log 任何内容

/* !!! */
let toformat = `
“Excuse me,” he said. The young woman didn’t respond. “What are you doing?” “Hey, I’m talking to you” Rudy said.
`
/* !!! */

let truef = false

/* !!! */
let run = true

/* !!! */

if(run){

  let res = []

  let dialogue = []
  let other = []
  let split = toformat.split('"').join('|"').split('|').slice(1)

  split.forEach((x, i) => {
    if(i % 2 == 1){
      other.push(x)
    } else {
      dialogue.push(x)
    }
  })



  for(let i = 0; i < dialogue.length; i++){
    res.push('\n' + dialogue[i] + '"')
    res.push(other[i].slice(1))
  }

  console.log(res.join(''))
  console.log(Math.random())

}

标签: javascriptconsole.log

解决方案



推荐阅读