JSX 字典中更改编辑表单的问题



我有一个带有输入字段的表单,用户可以在其中输入任何名称。我需要检查此名称是否已经存在,但在编辑字段中,它需要忽略其原始名称作为重复名称。

我正在寻找有关js方法的帮助

const isUnique = input => {
const dictionary = {};
// dictionary[iGetExistingNames] = 1
// so now the dictionary = {'a':1, 'b':1, 'c':1}
// how do I add new inputs as a key and set value to +1 and when backspace reduce the count?
// return bool 
}

您需要检查dictionary是否包含输入。如果没有,则添加它,否则它是重复的并增加计数。

// Say you have a dictionary with the key named john
const dictionary = {'john': 1}
// Check for the key using
dictionary['john']  // This should return 1.
// Add new keys using
dictionary[input] = 0;

最新更新