Q:

Javascript array how to properly clone values to another array . Angular 7

I have a component, and I want to add a value to the beginning of the array, but I have an error. Whats wrong, tell me please?
import { Component, OnInit } from '@angular/core';
import { DaoMockService } from '../../services/dao/dao-mock.service';
import { MatTableDataSource, } from '@angular/material';

@Component({
  selector: 'app-dynamic-table',
  templateUrl: './dynamic-table.component.html',
  styleUrls: ['./dynamic-table.component.css']
})
export class DynamicTableComponent implements OnInit {

  data;

  model = 
        {
            label: "Table label",
            extra: [
                "edit",
                "select"
            ],
            columns: [
                'color', 
                'desde', 
                'nombre'
            ]
        }

        dataFields: any[] = this.model.columns
        tableColumns: any[] = this.model.columns

  constructor(private dao: DaoMockService) { }

  ngOnInit() {
    this.createTable()
  }

  createTable() {

    console.log("dataFields --->", this.dataFields)
    // output: 
    // dataFields ---> (3) ["color", "desde", "nombre"]

    console.log("tableColumns --->",this.tableColumns)
    // output: 
    // tableColumns ---> (3) ["color", "desde", "nombre"]

    this.tableColumns.unshift("edit")

    console.log("dataFields --->", this.dataFields)
    // output: 
    // dataFields ---> (4) ["edit", "color", "desde", "nombre"]

    console.log("tableColumns --->",this.tableColumns)
    // output: 
    // tableColumns ---> (4) ["edit", "color", "desde", "nombre"]

    this.dao.getAll().subscribe( (res:any) => this.data = new MatTableDataSource(res.data.content))
  }

}

this.tableColumns.unshift("edit") unshifts both  dataFields and
 tableColumns arrays

A:

If you do 
dataFields: any[] = this.model.columns
     tableColumns: any[] = this.model.columns 

this means     dataFields: any[] = tableColumns: any[] = this.model.columns 
both varaiables store the reference to the same array 
Try this
 dataFields: any[] = this.model.columns
 tableColumns: any[] = [...this.model.columns] // Spread operator creates a new array and assings it to tableColumns

Read more here

