Javascript | React本机映射函数工作不正常

Javascript | React本机映射函数工作不正常,javascript,reactjs,react-native-android,Javascript,Reactjs,React Native Android,所以,我在与React Native合作时发现了一个非常愚蠢的问题,我似乎无法解决这个问题。我已经声明了一个带有一些硬编码值的对象数组(这里是storeVar)。当我尝试使用javascript映射函数循环遍历它时,我只得到第一个索引处的值。守则如下: import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, View, TextInput, ScrollView,

所以,我在与React Native合作时发现了一个非常愚蠢的问题,我似乎无法解决这个问题。我已经声明了一个带有一些硬编码值的对象数组(这里是storeVar)。当我尝试使用javascript映射函数循环遍历它时,我只得到第一个索引处的值。守则如下:

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  TextInput,
  ScrollView,
  AsyncStorage,
  TouchableOpacity
} from 'react-native';

import Note from './note.js'

// -------------------------------------------------------------------------


const storeVar = [
    {
        'd' : '',
        'n' : 'Hello'
    },
    {
        'd' : '',
        'n' : 'Awesome'
    },
];

export default class reactNativePractise extends Component {
    constructor(props) {
    super(props);
    this.state = {
        noteArray : [
            {
                'date' : '',
                'note' : ''
            }
        ],
    };
}

componentDidMount() { this.onLoad(); }

onLoad = async()=> {
    storeVar.map(async(value, index) => {
        try {
            var d = new Date();
            // const storedVal = [await AsyncStorage.getItem(storeVar[index].n)];
            alert("Key is : " + JSON.stringify(storeVar[index-1].n, null, 4));

            // this.state.noteArray.push( {date :d.getFullYear() + "/" + (d.getMonth()+1) + "/" + d.getDate(), note : storedVal[index]} );
        }
        catch(error) { alert('Error' + error) }
    });
}

只显示Hello,而不显示文本。任何帮助都将不胜感激。

不要使用
index-1
,请使用

JSON.stringify(storeVar[index].n, null, 4));
该索引将从
0
开始,因此执行
0
-1
将导致
-1
,并且当索引变为
1
时,它将无法访问
数组的-1
元素,并且
1-1
将在此时打印Hello(
0
索引元素)