我有一个接受“first_name”的数据库模型,但我希望它接受“名字”一词的不同版本。用户可能会尝试通过选择以“名字”或“名字”(注意它们之间的空格)的方式输入它来保存它。我希望它转换为“first_name”,以便可以将其保存在模型中
const str = " first name "; const result = str.trim().replace(/\s/g, "_"); console.log(result);