All Questions
Tagged with react-native arrays
1,294
questions
54
votes
10
answers
133k
views
React Native - Use a keyExtractor with FlatList
I have been getting the:
"VirtualizedList: missing keys for items, make sure to specify a key property on an item or provide a custom keyExtractor"
pretty confusing..., the array i am passing it ...
41
votes
3
answers
52k
views
React-Native Updating List View DataSource
I have an iOS app I am making with react-native. The Game class contains a ListView component. I set the state in the constructor and include a dataSource. I have a hardcoded array of data for right ...
29
votes
11
answers
35k
views
How to add a comma in array.map after every element except last element in React JSX
How can I add a trailing comma after every element of an array for making a list like:
INV, INV, INV, INV
Note that the last element doesn't have a trailing comma
Currently iterating the list with ...
20
votes
5
answers
161k
views
How to filter array of objects in react native?
I want to filter this data array into state and city array. How can I achieve this using lodash or any other better way rather than for loop and maintaining extra arrays.
data: [
{ id: 1, name: ...
12
votes
5
answers
17k
views
React Native - Dynamic Image Source
I'm trying to loop through the SOURCE array with the map method, but I keep getting this error:
Unknown named module: '../images/one.jpeg'
Anyone know why this is happening? The file path in the ...
11
votes
1
answer
31k
views
How to get the next element on Map function?
I'm trying to make some coordinate plane functions on React native. But I'm having a problem that I don't know how to get the next element on my array.
This is my array:
[
{"M":["0","0"]},
{"H":"100"...
11
votes
2
answers
3k
views
React Native: Rendering infinite number of pages (bi-directional swiping)
Question
How do people implement an infinite number of pages for you to swipe through dynamically?
Details
If an app renders a page for a day you can expect to swipe to the right for the previous day ...
11
votes
4
answers
4k
views
JavaScript Array flat function doesn't define in React native
I'm writing an application based on react-native and we know definitely we can use JavaScript codes in this project and all react projects.
But when I use below code the transpiler return Error to ...
9
votes
3
answers
11k
views
Javascript - Counting duplicates in object array and storing the count as a new object
I have an array of javascript objects that are products. These products are displayed in a list as a cart.
I want to count the number of duplicate products in the array based in the _.id value and ...
8
votes
9
answers
60k
views
Pushing To React State Array
How can I write this better , I want to do it with setState instead of this.state.floors.push as I know that is bad practice but I couldnt figure it out. Im using react native.
FloorAPI....
8
votes
3
answers
89k
views
how to get the index of selected element in react native array
I want an index of the selected element in the react native array. I tried with indexOf() but it always returns -1. School is my array & email contains the value of the element whose index to find....
7
votes
5
answers
16k
views
React Native: Array.map not rendering within Scrollview
I'm trying to render a list of items within a ScrollView Component from an array of data, but for some reason the items are not showing up, or perhaps rendering at all!? From the example below, only &...
6
votes
3
answers
30k
views
Add items to FlatList dynamically in React Native
I have a FlatList with two items. I need to append this list with another elements. When the user clicks on the button, the data from the text inputs should appear in the end of the FlatList. So, I've ...
6
votes
4
answers
35k
views
Reactjs how to initialize array object in state
I'm new to reactjs and i'm learning to change state in reactjs. I'm trying to initialize an array object in state with unknown length, and later update the array object using set state. Following is ...
6
votes
5
answers
2k
views
How to handle object and Array in react native?
Am actively creating a react native app for my college studies ! In that am using external api as data source. The problem am facing is that sometimes am getting data in single object and sometimes ...
5
votes
1
answer
23k
views
How to setState with an Array and object in Typescript?
This is how I declare a state
const [input, setInput] = React.useState('')
const [goals, setGoals] = React.useState<string[]>([])
and this is my error code:
const addHandler = () => {
...
5
votes
6
answers
266
views
Is it possible to print 16 times in React
I'm making an application. As an example, I tried to print the letter 'a' 16 times in the following code. But it didn't work. This is because I do use 'return'. I know that. But it does not use error. ...
5
votes
2
answers
90
views
How to setState on Object item within array
I want to update state of key heart in the array's objects when the heart icon pressed it changes to red so for this I'm using react native icons and i'm using heart and hearto to switch when click on ...
5
votes
4
answers
6k
views
How to call a function after map() loop executed
I'm using react-native firebase to save my media into firebase. I have a set of URLs that need to be saved in the firebase. For that, I'm using map() to save one by one. After saving I'm pushing the ...
5
votes
1
answer
3k
views
Array splice is not observed by mobx
I have defined an action for removing an item from an array:
export default class myStore {
@observable items = [];
...
...
@action deleteItem = async (target) => {
try {
await ...
5
votes
2
answers
432
views
How to play one video from array at a time in ReactJS & AG Grid
Getting response from API. API response
API response :
0:
Camera_Number: "Camera_1"
Company_Name: "Fraction Analytics Limited"
Floor Number: "Ground_Floor&...
4
votes
6
answers
18k
views
updating one value in State array react native
Trying to update one element of an array in this.state I'm getting an (expected ,) error but cant see where I've gone wrong. Do I need to create a temporary array update that, then assign the whole ...
4
votes
1
answer
18k
views
How to change value in array with index in react native [duplicate]
I have an array in my state:
state = {
some_array: [1,1,1,3,6,3,6,23], // sorry for the syntax it's changed
}
Now I want to change value in that array that has index let's say ...
4
votes
1
answer
3k
views
Add property to array of objects React Native
I use a library that calls an API which returns an array of objects:
new Promise((resolve) => {
Kit.getSamples(walkingSample, (err, results) => {
if (err) {
return resolve([])
}
...
4
votes
3
answers
3k
views
Updating property of object within stored array - React Native
I am using react-native-simple-store and have written the below function to update the property of a supplied object stored in an array of objects. To do so, I used the method mentioned in issue #31 ...
4
votes
3
answers
39k
views
How to map json data with array in react native
I have array like this in react native
const data = [
{ key: 1, label: 'Service1'},
{ key: 2, label: 'Service2' },
{ key: 3, label: 'Service3' },
{ key: 4, label: 'Service4' },
{...
4
votes
2
answers
7k
views
How to map through an array in React without ids?
I have a fairly standard array:
["value","value","value"]
If I want to iterate through it, each list item needs a unique key. But how would I do this in this case?
JSONs often come with an id -but ...
4
votes
2
answers
17k
views
React-native insert a value from render array to new array
What I'm trying to do is insert a value from the old array that I have render to the new array.
For now it can render the data that I want perfectly but when I push it into new array it become [id : ...
4
votes
1
answer
930
views
cannot delete array item, the wrong item always gets deleted
i have an ingredientsArray which is constructed by adding items from a drop down menu after pressing on a button, and then when i try to delete an item using deleteIngredient from this array by ...
4
votes
3
answers
6k
views
undefined on getting specific value from State array - React Native
I'm reading data from firestore and stores it in state array of objects.
when i
console.log(this.state.array)
it returns the whole array with all the data of the objects, but when i
console.log(this....
4
votes
3
answers
1k
views
saving and removing weekly schedule in async storage react native
I have a scenario in my project where i have to save weekly schedule with start and end time
What i want
user can enter day schedule with start and end
time and can remove.
Also i have ...
4
votes
1
answer
2k
views
JavaScript Arrays vs Objects performance
I am witnessing some magic over here.
First of all, this is a pretty common question and believe me I've done my research, so please before you mark this as duplicate, first hear me out.
The ...
3
votes
3
answers
23k
views
React Native - How to pass index in map function
I have a map function to create a component repetitively and dynamically. Suppose it's like this:
renderBoxes() {
return Array.map(data => this.myFunction(indexOfThisArray));
}
How can I ...
3
votes
2
answers
7k
views
Save an array of Items in AsyncStorage
How can I save an array of Items with AsyncStorage in react-native? So that every time you add another contact to your list it keeps adding up and not rewriting
Code:
saveContacts = ()=> {
try {...
3
votes
2
answers
19k
views
react native how to merge two arrays with a function
I have two functions and when I press each of them I create an array.
this.state = {
food:[],
sports:[],
interest:[],
}
_favoriteFood(...
3
votes
2
answers
6k
views
How can I speed up my array search function?
I am working on dictionary application written with react-native.
When I want to filter the array from the search box, I wrote below function. This is working quite good when I test with 2000 word ...
3
votes
3
answers
1k
views
How do I get my data into the correct format for React Native's SectionList?
I have an allPosts array that looks like this.
const allPosts = [
{
date: '2017-06-06',
imageUrl: 'image1_06-06',
},
{
date: '2017-06-06',
imageUrl: 'image2_06-06',...
3
votes
2
answers
17k
views
React Native: Key Value array or hasmap?
I would like to create an array/collection/hasmap in my react native app where a key is linked to a value. Cause I am coming from PHP I will give you a short example of what I mean. In PHP you simply ...
3
votes
1
answer
3k
views
How to show two columns in each row is Scrollview not Flatlist? React Native
I need to show an array and I need to render it using array.map not Flatlist because of the orientation issue.
In Flatlist, I can do it easily using numColumns = {2} but I really need to do that using ...
3
votes
4
answers
2k
views
How to map array of objects and return them as a new array of objects sorted in "categories" [duplicate]
I'm building my first react-native app and I want to show user some screen of his "followers" separated by categories but to do it I think I have to create new array of objects from this ...
3
votes
3
answers
12k
views
Get value in promise array
I'm using AsyncStorage from react-native to get and store data for my app. I successfully store data via AsyncStorage but when I try to getItem from AsyncStorage it
Promise {_40: 0, _65: 1, _55: "30"...
3
votes
2
answers
16k
views
How to initialise array in react-native using es6?
I am trying to create empty array in react-native using es6. But while accessing it I get an error data not defined.
Here is the code snippet which I am using to initialise the array.
constructor() {...
3
votes
1
answer
9k
views
Sending an array to a server to fetch some data with React Native
I am trying to do fetch a data from the server with given datas. I am using the following code :
const details = {
'function': 'getUsers',
};
const formBody =
Object.keys(...
3
votes
1
answer
4k
views
How can I create an interactive list with drag-and-drop functionality in React Native with Expo Go?
I'm looking to implement a list in my React Native app that allows users to rearrange items by dragging them up and down, effectively changing the order of the list. I've tried several npm packages, ...
3
votes
1
answer
699
views
How to remove children objects recursively from object?
I am working on solution
I have created basic tree kind of table whenever user click on expand data related to clicked row will appear under it based on row data
I have achieved basic functionality of ...
3
votes
1
answer
2k
views
deleting object elements from array using splice react native
I am trying to add and delete an obect from an array, I have been able to figure out the add object part, but the deletion is not working. I have used filter() but it did nothing. Now I am using ...
3
votes
1
answer
7k
views
Encrypt a byte array in JavaScript using crypto js AES ECB algorithm
I'm using an react native app to communicate with my miband 3, and part of its authentication process is encrypt a array of bytes using AES/ECB/NoPadding algorithm. I'm currently using this code as ...
3
votes
1
answer
8k
views
Sort and Group React Native SectionList by Key
I have a SectionList which I populate with data from firebase. The list shows event info sectioned by date, with the current month visible as THIS MONTH and the other dates using their shorthand value ...
3
votes
1
answer
4k
views
Updating Array Objects in Realm
I have a realm Organization and Ticket. An organization has many tickets. So to update organization, it looks like this:
try {
realm.write(() => {
realm.create('...
3
votes
3
answers
7k
views
How to make a key value pairs and push it to state in React?
My desired output will look like this
{'3afdrjke3j43kjkjf' : 3 , '8fsdfdsni3ni3dsfa' :2 }
I tried like this but it didn't work
const [productQuantity, setProductQuantity] = useState([]);
const ...