Friday, April 19, 2024

How to Push new values to reactjs array state?

How to Push new values to reactjs array state?

Hello friends, welcome again on my blog. Today in this blog post, I am going to tell you, How to Push new values to reactjs array state?

For reactjs new comers, please check the below link:

Reactjs Basic Tutorials

Friends here is the working code snippet for “How to Push new values to reactjs array state?” and please use this carefully to avoid mistakes:

1. Guys, here is the  code and I have added into my App.js file and you can add this whereever you want:

import React from 'react';
import './App.css';

class App extends React.Component {
  constructor(props) {
    this.state = {
      cars:['Range Rover', 'BMW', 'Mercedes-Benz']
      componentDidMount() {
        //Pushing New Values
        let arr =;
        arr.push('G Wagon', 'Jaguar', 'Skoda');
        this.setState({cars: arr});
  render() {

    return (
<div className="maincontainer">
  <h1> ReactJs</h1>
  { => {
            return (


export default App;


Now we are done friends. If you have any kind of query or suggestion or any requirement then feel free to comment below.

Note: Friends, I just tell the basic setup and things, you can change the code according to your requirements.
I will appreciate that if you will tell your views for this post.Nothing matters if your views will good or bad.



the authortherichpost
Hello to all. Welcome to Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.