title: How can i access a variable value from component1 in component2
body: <p>In <strong>component 1</strong> i have a function which returns a selected values from local storage using the code below, i wish to know is there any way to get the value of <code>this.array_no1</code> in <strong>component2</strong> so that i don't have to write this entire code again in <code>component2.component.ts</code> file. Please guide</p>
  
  <pre><code>ngOnInit() {
  //this.document.body.innerHTML += this.myname;
   var keys = Object.keys(localStorage).filter(function(key) {
    return /^section\d+$/.test(key);
  });
  
  var dataArray = keys.map(function(key) {
   return JSON.parse(localStorage.getItem(key));
  });
  
  for(var i=0;i&lt;dataArray.length;i++){
      var array_no = dataArray[i];
  }
   this.array_no1 = dataArray;
  console.log(this.array_no1);
    }
  </code></pre>