# How to get a reference to a CodeCell?

**URL:** <https://discourse.jupyter.org/t/how-to-get-a-reference-to-a-codecell/8517>\
**Category:** JupyterLab\
**Created:** [March 27, 2021, 12:15am UTC](https://discourse.jupyter.org/t/how-to-get-a-reference-to-a-codecell/8517 "2021-03-27T00:15:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adpatter](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/adpatter/32/21229_2.png) [@adpatter](https://discourse.jupyter.org/u/adpatter)\
**Post date:** [March 27, 2021, 12:15am UTC](https://discourse.jupyter.org/t/how-to-get-a-reference-to-a-codecell/8517/1 "2021-03-27T00:15:19Z")

</div>

I am able to iterate through the cells in a Notebook using the method below, however each cell implements ICellModel. In order to get the cell output I have cast the model to ICodeCellModel. However, what is the correct way to access the outputs of these Cells?

```
const extension: JupyterFrontEndPlugin<object> = {
  id: "etc-jupyterlab-telemetry:plugin",
  autoStart: true,
  requires: [INotebookTracker],
  activate: (app: JupyterFrontEnd, tracker: INotebookTracker) => {

tracker.widgetAdded.connect((tracker: INotebookTracker, nbPanel: NotebookPanel) => {

  nbPanel.revealed.then((r)=>{
    nbPanel.content.widgets.forEach(
      (cell: Cell<ICellModel>,
        index: number,
        array: readonly Cell<ICellModel>[]
      ) => {
        console.log((cell.model as ICodeCellModel).toJSON());
      })
  })
});
return {};
  }
};
```

---

<div class="post-metadata">

**Author:** ![jasongrout](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/jasongrout/32/371_2.png) [@jasongrout](https://discourse.jupyter.org/u/jasongrout)\
**Post date:** [March 27, 2021, 7:41am UTC](https://discourse.jupyter.org/t/how-to-get-a-reference-to-a-codecell/8517/2 "2021-03-27T07:41:34Z")

</div>

See isCodeCellModel: [jupyterlab/model.ts at b4db7f03d2ad0b91a9c8c252c56ae5e4a9408fbb · jupyterlab/jupyterlab · GitHub](https://github.com/jupyterlab/jupyterlab/blob/b4db7f03d2ad0b91a9c8c252c56ae5e4a9408fbb/packages/cells/src/model.ts#L143-L145)

---

<div class="post-metadata">

**Author:** ![adpatter](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/adpatter/32/21229_2.png) [@adpatter](https://discourse.jupyter.org/u/adpatter)\
**Post date:** [March 27, 2021, 12:35pm UTC](https://discourse.jupyter.org/t/how-to-get-a-reference-to-a-codecell/8517/3 "2021-03-27T12:35:34Z")

</div>

@jasongrout Thank you. I didn’t even know TypeScript had an `is` operator until today 🙂

I see how that works. Thanks again.
