簡體   English   中英

如何在對象數組中查找和比較單獨的對象值

[英]how to find and compare separate objects value in array of objects

我正在嘗試制作 React 注冊表單。

我的任務是為表單創建輸入字段並通過正則表達式檢查它們的值,並將密碼值和重復密碼與 email 進行比較。

沒關系,但檢查密碼和 r.password 的值很難

const fieldsValidation = () => {
  const newState = [...fieldsState];
  for (let [index, element] of newState.entries()) {

    if (element.value.length < element.valueLength) {
      return changeFields(() => {
        newState[index].error = true;
        return newState;
      });
    }
  };
  return registerUser();
};

這是我試圖與我的反應項目集成的配置

export const textFieldConfig = [{
    id: 'email',
    type: 'email',
    label: 'email',
    value: '',
    variant: 'outlined',
    size: 'small',
    error: false,
    helperText: 'email must include 8 char and @.',
    valueLength: 8
  },
  {
    id: 'password',
    type: 'password',
    label: 'password',
    value: '',
    variant: 'outlined',
    size: 'small',
    error: false,
    helperText: 'password must be min 6',
    valueLength: 6
  },
  {
    id: 'repeatPassword',
    type: 'password',
    label: 'repeat-password',
    value: '',
    variant: 'outlined',
    size: 'small',
    error: false,
    helperText: 'please include same password value',
    valueLength: 6
  }
];

我想如果你的 Object 沒有改變這會做

if(textFieldConfig[1].value == textFieldConfig[2].value){
....
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM